﻿using GraphQL.Types;
using GraphQLSample.Domain.Core;
using GraphQLSample.Domain.Services;
using System;
using System.Collections.Generic;
using System.Text;

namespace GraphQLSample.Domain.Schema
{
    public class UserType
        : ObjectGraphType<User>
    {
        public UserType(IRoleService roleService)
        {
            Name = nameof(User);
            Description = "";

            Field(t => t.Id);
            Field(t => t.Name);
            Field(t => t.RoleId);
            Field<SexEnumType>("gender", resolve: context => context.Source.Gender);

            Field<RoleType>("role", resolve: context => roleService.GetByIdAsync(context.Source.RoleId).Result);
        }
    }
}
